import os
import sys
import time
import json
import django
import uuid

BASE_DIR = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
print(os.path.abspath(__file__))
print(BASE_DIR)
sys.path.extend([BASE_DIR, ])
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "finance_c2c.settings")
django.setup()
from core.wchat.mini_base import wechat_client, wechat_client_howhow
from core.tools.oss_upload import oss_upload_file

from core.wchat.wx_base import mc

from django.contrib.auth import get_user_model


UserModel = get_user_model()



def create_minicode(data=4, page="pages/inviteNew/index", str_encode="Y"):
    if str_encode == "N":
        response = wechat_client.wxa.get_wxa_code_unlimited(data, page=page)
        url = oss_upload_file(response.content)
        print(url)
        return url
    else:
        key = uuid.uuid1().hex
        params = json.dumps(data)
        response = wechat_client.wxa.get_wxa_code_unlimited(key, page=page)
        mc.set(key, params)
        # print(key)
        url = oss_upload_file(response.content)
        print(url)
        return url

if __name__ == '__main__':
    create_minicode(data=4, str_encode="N")
